<template>
  <div class="mains" ref="questionBgk">
    <div class="top-header" @click="loginOut" v-if="isLogin">
      <van-icon color="#666" size="24" name="revoke" />
    </div>
    <lz-change-lang></lz-change-lang>
    <div class="titles">
<!--      {{ $t('夏日答题') }}-->
      {{dataForm.title}}
      <!--      <img src="@/assets/images/logo.png" alt="">-->
    </div>
    <div class="bottom-submit">
      <div class="btn-box">
        <div class="button" @click="toAnswer">
          {{ $t('立即答题') }}
        </div>
      </div>
      <div class="bottom-tip">
        <p v-if="isLogin">
          {{ userInfo.username }}
          {{ $t('剩余答题次数') }}
          <span>{{ (dataForm.countLimit - userInfo.answerCount).toFixed(0)}}</span>
          {{$t('次')}}
        </p>
<!--        <p v-if="isLogin">-->
<!--          {{ userInfo.username }},{{ $t('您还有') }}-->
<!--          <span>{{ userInfo.cjCount || 0 }}</span>-->
<!--          {{ $t('次机会参与此活动') }}-->
<!--        </p>-->
        <div class="btn-1" @click="openPrize" v-if="false">
          <div class="button1">
            {{ $t('我的奖品') }}
          </div>
        </div>
      </div>

      <div class="table">
        <div class="gift">
          <div class="titles-gif">
            <span>{{ $t('他们都答题成功了') }}</span>
            <span></span>
          </div>
          <lz-animate-list class="box" :speed="0.5" ref="listScroll">
            <div class="list">
              <div class="item" v-for="(item,index) in lists" :key="index">
                <div class="left">
                  <img src="@/assets/images/icon-account.png" alt="">
                  <span>{{ item.userName }}</span>
                </div>
                <span class="gift_name">{{
                    item.prizeName ? item.prizeName.length > 8 ? item.prizeName.slice(0, 8) + '...' : item.prizeName : ''
                  }}</span>
                <span class="time">{{ parseTime(item.addTime).slice(0, 10) }}</span>
              </div>
            </div>
          </lz-animate-list>
        </div>
      </div>
      <div class="table">
        <div class="gift">
          <div class="titles-gif">
            <span>{{ $t('项目描述') }}</span>
            <span></span>
          </div>
          <div class="content">
            <span v-html="dataForm.explanation ? dataForm.explanation : ''"></span>

          </div>
        </div>
      </div>

      <lz-login :login-show="loginShow" @closeLogin="closeLogin"/>
      <lz-list
          :is-show="ListShow"
          @closeList="closeList"
      />

      <lz-lottery
          :lottery-value="lotteryValue"
          :lottery-show="isLottery"
          @closeLottery="closeLottery"
      />
    </div>
  </div>
</template>

<script>

import {parseTime} from "@/utils";
import {getQuestionAct, homeIndex, userDetail} from "@/api/apiFox";
import lzChangeLang from '@/components/change-lang.vue'
import LzLogin from '@/components/login.vue'
import lzLottery from '@/components/lottery.vue'
import lzList from '@/components/List.vue'
import LzAnimateList from '@/components/animateList.vue'
import {Dialog} from "vant";

export default {
  components: {LzLogin, lzLottery, lzList, LzAnimateList,lzChangeLang},
  data() {
    return {
      lists: [],
      formData: {},
      isLogin: false,
      ListShow: false,
      isLottery: false,
      loginShow: false,
      lotteryValue: '',
      userInfo: {},
      dataForm:{} //答题活动基本信息
    }
  },
  methods: {
    parseTime,
    getIndexData() {
      homeIndex().then(res => {
        console.log(res.lotteryRecord)
        // this.tableData = res.prize
        this.formData = res
        this.lists = res.lotteryRecord ? res.lotteryRecord : []
        console.log(this.lists)
      }).catch(err => {})
    },
    getQuestionList(){
      getQuestionAct().then(res=>{
        console.log(res)
        this.dataForm=res
        this.$refs.questionBgk.style.background=`url(${res.actBackgroundImg}) no-repeat`
        this.$refs.questionBgk.style.backgroundSize=`100% 100%`
      }).catch(err=>{})
    },
    toAnswer(){
      if (this.isLogin){
        if (this.userInfo.answerCount>=this.dataForm.countLimit){
          Dialog.alert({
            title: this.$t('提示'),
            message: this.$t('当前答题次数已用完'),
            confirmButtonText:this.$t('确定')
          }).then(() => {

          });
        }else{
          this.$router.push('/question').catch(err=>{})
        }

      }else{
        Dialog.alert({
          title: this.$t('提示'),
          message: this.$t('当前没有登录是否去登录'),
          confirmButtonText:this.$t('确定')
        }).then(() => {
          this.loginShow=true
        });
      }
    },
    getList() {
      this.getUserInfo()
    },
    getUserInfo() {
      if (this.isLogin) {
        this.getIndexData()
        userDetail().then(res => {
          this.userInfo = res
        }).catch(err => {})
      } else {
        this.getIndexData()
      }
    },
    toLogin() {
      console.log(11111)
      this.loginShow = true
    },
    closeList() {
      this.ListShow = false
    },
    closeLottery() {
      this.isLottery = false
      this.starting = false
      this.getList()
    },
    openPrize() {
      this.ListShow = true
    },
    closeLogin() {
      this.loginShow = false
      let s = localStorage.getItem('accessKey')
      let d = sessionStorage.getItem('userInfo')
      if (s && d) {
        this.isLogin = true
        this.getList()
      } else {
        this.isLogin = false
      }
    },
    loginOut(){
      localStorage.clear()
      sessionStorage.clear()
      this.userInfo = ''
      this.$store.state.token = ''
      this.isLogin = false
    }
  },
  mounted() {
    this.getQuestionList()
    this.getIndexData()
  },
  created() {
    let s = localStorage.getItem('accessKey')
    let d = sessionStorage.getItem('userInfo')
    if (s && d) {
      this.isLogin = true
    } else {
      this.isLogin = false
    }
    this.getList()
  }
}
</script>

<style scoped lang="scss">
.mains {
  font-size: 14px;
  background: url("@/assets/images/bgk.jpg") no-repeat;
  background-size: 100% 100%;
  width: 100%;
  min-height: 100vh;
  padding-top: 45px;
  box-sizing: border-box;
  .top-header{
    width: 100%;
    position: absolute;
    top: 20px;
    left: 20px;
    pointer-events: auto;
    font-family: 'Fugaz One', sans-serif;
    font-weight: 800;
  }
  .titles {
    width: 100%;
    min-height: 80px;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 36px;
    color: #ff9e67;
    font-family: 'AnimeHug', sans-serif;
    text-shadow: -1px -1px 0 #fff,
    1px -1px 0 #fff,
    -1px 1px 0 #fff,
    1px 1px 0 #fff; // 白色描边
    img {
      height: 100px;
    }
  }

  &::-webkit-scrollbar {
    width: 0;
  }

  .bottom-submit {
    width: 100%;
    padding: 0 5px;
    box-sizing: border-box;
    margin-top: 30vh;

    .btn-box {
      width: 100%;
      display: flex;
      justify-content: center;

      .button {
        width: 220px;
        height: 55px;
        background: url("@/assets/images/btn.png") no-repeat;
        background-size: 100% 100%;
        font-size: 14px;
        color: #ff0000;
        display: flex;
        justify-content: center;
        align-items: center;
        font-family: 'AnimeHug', sans-serif;
        text-shadow: -1px -1px 0 #fff,
        1px -1px 0 #fff,
        -1px 1px 0 #fff,
        1px 1px 0 #fff; // 白色描边
      }
    }

    .bottom-tip {
      width: 100%;
      text-align: center;
      margin-top: 15px;
      margin-bottom: 45px;

      p {
        width: 100%;
        font-size: 14px;
        color: #fff;
        margin-top: 5px;
        font-family: 'AnimeHug', sans-serif;
        text-shadow: -1px -1px 0 #ff9e67,
        1px -1px 0 #ff9e67,
        -1px 1px 0 #ff9e67,
        1px 1px 0 #ff9e67;

        span {
          color: #ff5354;
          font-size: 18px;
        }
      }

      .btn-1 {
        width: 100%;
        display: flex;
        justify-content: center;
        margin: 15px 0;

        .button1 {
          width: 150px;
          height: 40px;
          background: url('@/assets/images/btn.png') no-repeat;
          background-size: 100% 100%;
          font-size: 14px;
          color: #ff0000;
          display: flex;
          justify-content: center;
          align-items: center;
          font-family: 'AnimeHug', sans-serif !important;
          text-shadow: -1px -1px 0 #fff,
          1px -1px 0 #fff,
          -1px 1px 0 #fff,
          1px 1px 0 #fff; // 白色描边
        }
      }
    }

    .table {
      width: 100%;
      min-height: 150px;
      margin-top: 15px;
      padding: 0 3%;
      box-sizing: border-box;

      .gift {
        border-radius: 15px;
        width: 100%;
        min-height: 100px;
        background: #feefcc;

        .titles-gif {
          width: 100%;
          height: 40px;
          padding: 0 5%;
          box-sizing: border-box;
          border-top-right-radius: 15px;
          border-top-left-radius: 15px;
          background-image: linear-gradient(#ecb844, #E3B95B);
          display: flex;
          justify-content: space-between;
          align-items: center;
          font-family: 'AnimeHug', sans-serif;
          text-shadow: -1px -1px 0 #fff,
          1px -1px 0 #fff,
          -1px 1px 0 #fff,
          1px 1px 0 #fff; // 白色描边
          span {
            font-size: 15px;
            color: #cb1b0f;
            font-weight: 600;
          }
        }

        .box {
          padding: 3% 5%;
          box-sizing: border-box;
          width: 100%;
          height: 250px;
          font-size: 13px;
          overflow-y: scroll;

          .item {
            width: 100%;
            height: 40px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px #e7c09c dashed;

            .left {
              width: 100px;
              height: 50px;
              display: flex;
              align-items: center;
              color: #ff8e0c;
              font-family: 'Fugaz One', sans-serif;
              text-shadow: -1px -1px 0 #fff,
              1px -1px 0 #fff,
              -1px 1px 0 #fff,
              1px 1px 0 #fff; // 白色描边
              img {
                margin-right: 10px;
                width: 26px;
                height: 26px;
                border-radius: 50%;
              }

            }

            .gift_name {
              width: 150px;
              margin-left: 10px;
              font-family: 'Fugaz One', sans-serif;
              color: #ff8e0c;
              text-shadow: -1px -1px 0 #fff,
              1px -1px 0 #fff,
              -1px 1px 0 #fff,
              1px 1px 0 #fff; // 白色描边
              text-align: center;
            }

            .time {
              width: 140px;
              float: right;
              font-family: 'Fugaz One', sans-serif;
              color: #ff8e0c;
              text-shadow: -1px -1px 0 #fff,
              1px -1px 0 #fff,
              -1px 1px 0 #fff,
              1px 1px 0 #fff; // 白色描边
            }
          }

          &::-webkit-scrollbar {
            width: 0;
          }
        }

        .content {
          text-indent: 15px;
          font-size: 15px;
          color: #cb1b0f;
          padding: 3%;
          box-sizing: border-box;
        }
      }
    }
  }
}
</style>
